from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d):
        super().__init__(d)

    def get_name(self):
        return "这城有良田"

    def game_alert(self):
        while True:
            if self.alert_close('./game/img/这城有良田/alert.png'):
                continue
            if self.alert_close('./game/img/这城有良田/alert01.png'):
                continue
            if self.alert_close('./game/img/这城有良田/alert02.png'):
                continue
            break

    def handle_main(self):
        self.log_msg("等待进入游戏")
        self.img_exit('./game/img/这城有良田/start.png', 20)
        self.log_msg("已进入游戏")
        self.game_alert()
        #
        self.log_msg("点击登陆游戏")
        self.img_click('./game/img/这城有良田/start.png')

        self.img_exit('./game/img/这城有良田/game_main.png', 100)
        self.log_msg("已进入游戏主界面")
        self.d.sleep(5)
        self.swipe_left()
        self.img_click_if_exists('点击不良司', './game/img/这城有良田/play.png', './game/img/这城有良田/play01.png')
        self.img_click_if_exists('点击通缉', './game/img/这城有良田/play01.png', './game/img/这城有良田/play02.png')
        self.log_msg("点击追捕")
        self.img_click('./game/img/这城有良田/play02.png')
        while True:
            if self.img_exit('./game/img/这城有良田/win.png', 5):
                self.log_msg("追捕完成")
                break

            done = False
            for i in range(5):
                self.log_msg(f"追捕中-{i}")
                ok = self.img_click('./game/img/这城有良田/play03.png')
                if not ok:
                    self.log_msg("追捕完成")
                    done = True
                    break
            if done:
                break

        self.click_bottom()
        self.click_bottom()
        self.img_click_if_exists('点击添加', './game/img/这城有良田/win01.png', './game/img/这城有良田/win03.png')
        self.img_click_if_exists('点击联合', './game/img/这城有良田/win03.png', './game/img/这城有良田/win02.png')
        self.log_msg("点击押运")
        self.img_click('./game/img/这城有良田/win02.png')
        self.click_bottom()

        return True
